<?php

namespace app\nideshop\controller;

use think\Db;

/**
 * 专题
 */
class Topic extends Base
{
    protected $datas;

    /**
     * 专题页面接口
     * fanqunxing
     */
    public function listAction()
    {
        $this->datas = $this->params;
        $page = (int) $this->datas['page'];
        $size = (int) $this->datas['size'];
        if (empty($page)) {
            $page = 1;
        }
        if (empty($size)) {
            $size = 10;
        }
        $data = Db::name('topic')
            ->field('id,title,price_info,scene_pic_url,subtitle')
            ->paginate($size, false, ['page' => $page]);

        return json(
            [
                'errno' => 0,
                'errmsg' => '成功',
                'data' => [
                    'count' => $data->total(),
                    'totalPages' => $data->lastPage(),
                    'pageSize' => $size,
                    'currentPage' => $page,
                    'data' => $data->items()
                ]
            ]
        );
    }
    
    /**
     * 获取专题详情
     */
    public function detailAction() {
        $this->datas = $this->params;
        $id = (int) $this->datas['id'];
        $data = Db::name('topic')
        ->where('id', $id)
        ->find();
        return json(
            [
                'errno' => 0,
                'errmsg' => '成功',
                'data' => $data
            ]
        );
    }

    /**
     * 获取相关推荐
     */
    public function relatedAction() {
        $data = Db::name('topic')
        ->field('id,title,price_info,scene_pic_url,subtitle')
        ->limit(4)
        ->select();
        return json(
            [
                'errno' => 0,
                'errmsg' => '成功',
                'data' => $data
            ]
        );
    }
}
